package com.ukao.cashregister.ui.statistics;


import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.ukao.cashregister.R;
import com.ukao.cashregister.base.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import info.hoang8f.android.segmented.SegmentedGroup;

/**
 * 营收分析
 */
public class StatisticsTabFragment extends BaseFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";


    Unbinder unbinder;
    @BindView(R.id.tab_one)
    RadioButton tabOne;
    @BindView(R.id.tab_two)
    RadioButton tabTwo;
    @BindView(R.id.segmented_group)
    SegmentedGroup segmentedGroup;
    @BindView(R.id.content_layout)
    FrameLayout contentLayout;
    @BindView(R.id.back_btn)
    TextView backBtn;

    private String mParam1;
    private String mParam2;
    private BaseFragment[] mFragment = new BaseFragment[2];


    public static StatisticsTabFragment newInstance(String param1, String param2) {
        StatisticsTabFragment fragment = new StatisticsTabFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_statistics_tab, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initListener();
    }

    @Override
    protected void initView() {

        mFragment[0] = StatisticDetailsFragment.newInstance("1", "");
        mFragment[1] = StatisticDetailsFragment.newInstance("2", "");
        loadMultipleRootFragment(R.id.content_layout, 0,
                mFragment);
        tabOne.setChecked(true);
    }

    @Override
    protected void initListener() {
        super.initListener();
        segmentedGroup.setOnCheckedChangeListener(mOnCheckListener);
    }


    private RadioGroup.OnCheckedChangeListener mOnCheckListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
                case R.id.tab_one:
                    showHideFragment(mFragment[0]);
                    break;
                case R.id.tab_two:
                    showHideFragment(mFragment[1]);
                    break;

                default:
            }
        }

    };


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.back_btn })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                finish();
                break;



        }
    }





}
